package com.feng.controller;

import com.feng.entity.User;
import com.feng.entity.Order;
import com.feng.feign.UserServiceClient;
import com.feng.feign.OrderServiceClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/feign")
public class FeignController {
    @Autowired
    private UserServiceClient userServiceClient;
    
    @Autowired
    private OrderServiceClient orderServiceClient;

    // 用户相关接口
    @GetMapping("/user/findAll")
    public List<User> findAllUsers(){
        return userServiceClient.findAllUsers();
    }

    @GetMapping("/user/findById/{id}")
    public User findUserById(@PathVariable("id") Integer id){
        return userServiceClient.findUserById(id);
    }
    
    @PostMapping("/user/save")
    public User saveUser(@RequestBody User user){
        return userServiceClient.saveUser(user);
    }
    
    @PutMapping("/user/update")
    public User updateUser(@RequestBody User user){
        return userServiceClient.updateUser(user);
    }
    
    @DeleteMapping("/user/deleteById/{id}")
    public void deleteUserById(@PathVariable("id") Integer id){
        userServiceClient.deleteUserById(id);
    }

    // 订单相关接口
    @GetMapping("/order/findAll")
    public List<Order> findAllOrders(){
        return orderServiceClient.findAllOrders();
    }

    @GetMapping("/order/findById/{id}")
    public Order findOrderById(@PathVariable("id") Long id){
        return orderServiceClient.findOrderById(id);
    }
    
    @GetMapping("/order/findByUserId/{userId}")
    public List<Order> findOrdersByUserId(@PathVariable("userId") Long userId){
        return orderServiceClient.findOrdersByUserId(userId);
    }
    
    @PostMapping("/order/save")
    public Order saveOrder(@RequestBody Order order){
        return orderServiceClient.saveOrder(order);
    }
    
    @PutMapping("/order/update")
    public Order updateOrder(@RequestBody Order order){
        return orderServiceClient.updateOrder(order);
    }
    
    @DeleteMapping("/order/deleteById/{id}")
    public void deleteOrderById(@PathVariable("id") Long id){
        orderServiceClient.deleteOrderById(id);
    }
}